package com.codebo.homiematchbackend.controller;

import com.codebo.homiematchbackend.annotation.AuthCheck;
import com.codebo.homiematchbackend.common.BaseResponse;
import com.codebo.homiematchbackend.common.ErrorCode;
import com.codebo.homiematchbackend.common.ResultUtils;
import com.codebo.homiematchbackend.constant.UserConstant;
import com.codebo.homiematchbackend.exception.ThrowUtils;
import com.codebo.homiematchbackend.model.entity.User;
import com.codebo.homiematchbackend.model.vo.ChatRecordVO;
import com.codebo.homiematchbackend.service.ChatService;
import com.codebo.homiematchbackend.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChatController
{
    @Resource
    private ChatService chatService;

    @Resource
    private UserService userService;

//    @PostMapping("/send")
//    public BaseResponse<Boolean> sendMessage(ChatRequest chatRequest)
//    {
//        ThrowUtils.throwIf(chatRequest == null, ErrorCode.PARAMS_ERROR, "请求参数为空");
//        boolean result = chatService.sendMessage(chatRequest);
//        return ResultUtils.success(result);
//    }
//    @GetMapping("/redord")

    @AuthCheck(mustRole = UserConstant.DEFAULT_ROLE)
    @GetMapping("/record")
    public BaseResponse<List<ChatRecordVO>> getChatRecord(Long id)
    {
        ThrowUtils.throwIf(id <= 0, ErrorCode.PARAMS_ERROR);
        User user = userService.getById(id);
        ThrowUtils.throwIf(user == null, ErrorCode.NOT_FOUND_ERROR, "用户id错误");

        List<ChatRecordVO> chatRecordVOList = chatService.getChatRecord(id);
        return ResultUtils.success(chatRecordVOList);
    }


}
